package com.ruoyi.mall.cms.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.cms.domain.CmsSubjectCategory;
import com.ruoyi.mall.cms.service.ICmsSubjectCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专题分类Controller
 * 
 * @author xuxing
 * @date 2021-02-05
 */
@RestController
@RequestMapping("/cms/subjectCategory")
public class CmsSubjectCategoryController extends BaseController
{
    @Autowired
    private ICmsSubjectCategoryService cmsSubjectCategoryService;

    /**
     * 查询专题分类列表
     */
    @PreAuthorize("@ss.hasPermi('cms:subjectCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsSubjectCategory cmsSubjectCategory)
    {
        startPage();
        List<CmsSubjectCategory> list = cmsSubjectCategoryService.selectCmsSubjectCategoryList(cmsSubjectCategory);
        return getDataTable(list);
    }

    /**
     * 导出专题分类列表
     */
    @PreAuthorize("@ss.hasPermi('cms:subjectCategory:export')")
    @Log(title = "专题分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CmsSubjectCategory cmsSubjectCategory)
    {
        List<CmsSubjectCategory> list = cmsSubjectCategoryService.selectCmsSubjectCategoryList(cmsSubjectCategory);
        ExcelUtil<CmsSubjectCategory> util = new ExcelUtil<CmsSubjectCategory>(CmsSubjectCategory.class);
        return util.exportExcel(list, "subjectCategory");
    }

    /**
     * 获取专题分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:subjectCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmsSubjectCategoryService.selectCmsSubjectCategoryById(id));
    }

    /**
     * 新增专题分类
     */
    @PreAuthorize("@ss.hasPermi('cms:subjectCategory:add')")
    @Log(title = "专题分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsSubjectCategory cmsSubjectCategory)
    {
        return toAjax(cmsSubjectCategoryService.insertCmsSubjectCategory(cmsSubjectCategory));
    }

    /**
     * 修改专题分类
     */
    @PreAuthorize("@ss.hasPermi('cms:subjectCategory:edit')")
    @Log(title = "专题分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsSubjectCategory cmsSubjectCategory)
    {
        return toAjax(cmsSubjectCategoryService.updateCmsSubjectCategory(cmsSubjectCategory));
    }

    /**
     * 删除专题分类
     */
    @PreAuthorize("@ss.hasPermi('cms:subjectCategory:remove')")
    @Log(title = "专题分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsSubjectCategoryService.deleteCmsSubjectCategoryByIds(ids));
    }
}
